package threadcoreknowledge.createthread.sixstates;

/**
 * 线程的前三个状态:new,runnable,terminated 三个状态
 * 即使是正在运行也是runnable,而不是running
 *
 * @Author Li Cheng
 * @Date 2021/8/11 15:11
 * @Version 1.0
 */
public class NewRunnableTerminated  implements  Runnable{

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new NewRunnableTerminated());

        //打印 new 状态
        System.out.println(thread.getState());
        thread.start();
        Thread.sleep(10);
        //打印出runnable状态，即使正在运行，也是runnable,而不是running
        //他会在执行过程中打印runnable
        System.out.println(thread.getState());

        Thread.sleep(100);
        //当所有的run执行完毕
        System.out.println(thread.getState());
    }



    @Override
    public void run() {
        for (int i=0 ; i<1000 ; i++)
            System.out.println(i);
    }
}
